package main

import (
	"fmt"
	"math/rand"
)

func main(){
	// basic usage
	names:=[]string{"Golang","Java","Rust","C"}
	switch name:=names[0];name{
		case "Rust":
			fmt.Println("A programming language from Mozilla.")
		case "Golang":
			fmt.Println("A programming language from Google.")
			fallthrough
		default:
			fmt.Println("Unknown!")
	}
	// type switch
	ia:=[]interface{}{byte(6),'a',uint(10),int32(-4)}
	switch v:=ia[rand.Intn(4)%2];interface{}(v).(type){
		case int32:
			fmt.Println("Case A.")
		case byte:
			fmt.Println("Case B.")
		default:
			fmt.Println("Unknown!")
	}
	// condition match
	value:=3
	switch{
	case value < 2:
		fallthrough
	case value > 5:
		fmt.Println("Out of range!")
	default:
		fmt.Println("Legal value.")
	}
}